#include "insert_sort.h"
#include "common/common.h"
#include "common/array.h"

void insert_sort_impl(int array[], int size) {
  int i, j, tmp;

  for (i = 1; i < size; ++i) {
    tmp = array[i];
    for (j = i; j > 0 && array[j - 1] > tmp; --j) {
      array[j] = array[j - 1];
    }
    array[j] = tmp;
  }
}

void insert_sort(array_t *array) {
  insert_sort_impl(array->data, array->size);
}
